<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="代征主体" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dzzt">
              <a-input v-model="model.dzzt" placeholder="请输入代征主体"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qymc">
              <a-input v-model="model.qymc" placeholder="请输入企业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="法定代表人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fddbr">
              <a-input v-model="model.fddbr" placeholder="请输入法定代表人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属销售" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ssxs">
              <j-dict-select-tag type="list" v-model="model.ssxs" dictCode="bu_gsfwpt_xsgl,name,id" placeholder="请选择所属销售" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lxr">
              <a-input v-model="model.lxr" placeholder="请输入联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lxdh">
              <a-input v-model="model.lxdh" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售签约费率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xsqyfl">
              <a-input v-model="model.xsqyfl" placeholder="请输入销售签约费率"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业签约费率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qyqyfl">
              <a-input v-model="model.qyqyfl" placeholder="请输入企业签约费率"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="扣款方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kkfs">
              <j-dict-select-tag type="list" v-model="model.kkfs" dictCode="kk_type" placeholder="请选择扣款方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开票电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kpdh">
              <a-input v-model="model.kpdh" placeholder="请输入开票电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属省/市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sss">
<!--
              <j-dict-select-tag type="list" v-model="model.sss" dictCode="sj_code" placeholder="请选择所属省" />

-->           <j-area-linkage type='cascader' v-model="model.sss" placeholder="请选择所属省/市" ></j-area-linkage>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开票地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kpdz">
              <a-input v-model="model.kpdz" placeholder="请输入开票地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开票类目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kplm">
              <a-input v-model="model.kplm" placeholder="请输入开票类目"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="签约时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qysj">
              <j-date placeholder="请选择签约时间" v-model="model.qysj"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同是否归档" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htsfgd">
              <j-dict-select-tag type="list" v-model="model.htsfgd" dictCode="ht_sfgd" placeholder="请选择合同是否归档" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合同是否到期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htsfdq">
              <j-dict-select-tag type="list" v-model="model.htsfdq" dictCode="ht_sfdq" placeholder="请选择合同是否到期" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮箱号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yxh">
              <a-input v-model="model.yxh" placeholder="请输入邮箱号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮寄地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yjdz">
              <a-input v-model="model.yjdz" placeholder="请输入邮寄地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wslx">
              <j-dict-select-tag type="list" v-model="model.wslx" dictCode="bu_jygl_wslx" placeholder="请选择业务类型" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BuGsfwptQyxxForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          dzzt: [
            { required: true, message: '请输入代征主体!'},
          ],
          qymc: [
            { required: true, message: '请输入企业名称!'},
          ],
          fddbr: [
            { required: true, message: '请输入法定代表人!'},
          ],
          ssxs: [
            { required: true, message: '请输入所属销售!'},
          ],
           kpdh: [
              { required: false},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
           yxh: [
              { required: false},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
           ],
          wslx: [
            { required: true, message: '请输入业务类型!'},
          ],
        },
        url: {
          add: "/qyxx/buGsfwptQyxx/add",
          edit: "/qyxx/buGsfwptQyxx/edit",
          queryById: "/qyxx/buGsfwptQyxx/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>